<?php

declare(strict_types=1);
/**
 * @copyright 深圳市易果网络科技有限公司
 * @version 1.0.0
 * @link https://dayiguo.com
 */

namespace App\Controller\business\v2;

use App\Middleware\User\UserMiddleware;
use App\Request\Business\Coupon\AddCouponRequest;
use App\Request\Business\Coupon\AddShopDiscountRequest;
use App\Request\Business\Coupon\AddVoucherRequest;
use App\Request\Business\Coupon\DeleteCouponRequest;
use App\Service\Business\v2\CouponService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\AutoController;
use Hyperf\HttpServer\Annotation\Middleware;
use Hyperf\Snowflake\IdGeneratorInterface;
use Hyperf\Utils\ApplicationContext;
use App\Controller\Business\Controller;
/**
 * 优惠券控制器
 *
 * @AutoController()
 * @Middleware(UserMiddleware::class)
 * @author 张昊(2396675557@qq.com)
 * @package App\Controller\business
 */
class CouponController extends Controller
{

    /**
     * @Inject
     * @var CouponService
     */
    public $service;

    /**
     * 添加全店打折信息
     *
     * @param AddShopDiscountRequest $request
     */
    public function addShopDiscount(AddShopDiscountRequest $request)
    {
        $params = $request->all();

        $result = $this->service->addShopDiscount($params);

        $this->success($result);
    }

    /**
     * 添加优惠券
     *
     * @param AddCouponRequest $request
     */
    public function addCoupon(AddCouponRequest $request)
    {
        $params = $request->all();

        $this->service->addCoupon($params);

        $this->success();
    }

    /**
     * 添加现金抵用券信息
     *
     * @param AddVoucherRequest $request
     */
    public function addVoucher(AddVoucherRequest $request)
    {
        $params = $request->all();

        $result = $this->service->addVoucher($params);

        $this->success($result);
    }

    /**
     * 获取全店打折数据
     */
    public function getShopDiscount()
    {
        $type = (int)$this->request->input('type', 1);

        $result = $this->service->getShopDiscount($type);

        $this->success($result);
    }

    /**
     * 获取商家的优惠券列表
     *
     */
    public function getCouponList()
    {
        $type = (int)$this->request->input('type', 1);

        $result = $this->service->getCouponList($type);

        $this->success($result);
    }

    /**
     * 获取现金抵用券列表
     *
     */
    public function getVoucherList()
    {
        $type = (int)$this->request->input('type', 1);

        $result = $this->service->getVoucherList($type);

        $this->success($result);
    }

    /**
     * 删除优惠券
     *
     * @param DeleteCouponRequest $request
     */
    public function deleteCoupon(DeleteCouponRequest $request)
    {
        $params = $request->all();

        isset($params['ids']) && $params['ids'] = (array)$params['ids'];

        $this->service->deleteCoupon($params['ids']);

        $this->success();
    }
}